#!/usr/bin/env python
#
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""A simple example of matcher API interacting with XMPP.
   This application implements an XMPP chat bot that distributes chat mesasges
   to users based on subscriptions that they have registered.
   Users need to first add the chat bot to their buddy lists. Then, they
   can enter subscriptions to messages. For instance, the command:
     /subscribe track:"red rose"
   would cause all messages containing the phrase "red rose" to be sent
   to the subscriber. A user can also subscribe to any message from a particular
   user. For instance, the subscription:
     /subscribe follow:bob@example.com
   would result in all messages entered by bob@example.com being delivered.
   Any message not preceded by the command character "/" is matched against all
   registered subscriptions in real-time.
"""
# Override use of default Django version by explicitly setting version to use.
# See: http://code.google.com/appengine/docs/python/tools/libraries.html#Django
from google.appengine.dist import use_library
use_library('django', '1.2')

import os
import sys

from google.appengine.api.app_identity import get_application_id

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util


class HelloPage(webapp.RequestHandler):
  """Displays the application introduction and detailed help."""

  def get(self):
    domain = 'appspot.com'
    app_id = get_application_id()
    app_jid = '%s@%s' % (app_id, domain)
    template_values = {'app_jid': app_jid,}
    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, template_values))


def main(argv):
  application = webapp.WSGIApplication(
      [('/', HelloPage),
      ], debug=True)
  util.run_wsgi_app(application)

if __name__ == '__main__':
  main(sys.argv)
